package com.example.myapplication.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.adapter.LiveAdapter;
import com.example.myapplication.bean.LiveDataBean;

import java.util.ArrayList;
import java.util.List;

public class LiveListFragment extends Fragment {
    private Context mContext;
    private RecyclerView recyclerView;
    private LiveAdapter adapter;

    public static LiveListFragment newInstance() {
        return new LiveListFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        return inflater.inflate(R.layout.fragment_live_list, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        recyclerView = view.findViewById(R.id.rv);
        adapter = new LiveAdapter(mContext);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3));
//        MyViewDecoration decor = new MyViewDecoration(mContext, LinearLayoutManager.VERTICAL,20, Color.TRANSPARENT);
//        recyclerView.addItemDecoration(decor);
        loadData();
    }

    // TODO: 2020/12/2 模拟假数据
    private void loadData() {
        List<LiveDataBean> data = new ArrayList<>();
        data.add(new LiveDataBean("https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00553-3963.jpg", 100));
        data.add(new LiveDataBean("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1186710844,269686722&fm=15&gp=0.jpg", 100));
        data.add(new LiveDataBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1592679528,3428712183&fm=26&gp=0.jpg", 500));
        data.add(new LiveDataBean("https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00553-3963.jpg", 100));
        data.add(new LiveDataBean("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1186710844,269686722&fm=15&gp=0.jpg", 100));
        data.add(new LiveDataBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1592679528,3428712183&fm=26&gp=0.jpg", 500));
        data.add(new LiveDataBean("https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00553-3963.jpg", 100));
        data.add(new LiveDataBean("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1186710844,269686722&fm=15&gp=0.jpg", 100));
        data.add(new LiveDataBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1592679528,3428712183&fm=26&gp=0.jpg", 500));
        data.add(new LiveDataBean("https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00553-3963.jpg", 100));
        data.add(new LiveDataBean("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1186710844,269686722&fm=15&gp=0.jpg", 100));
        data.add(new LiveDataBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1592679528,3428712183&fm=26&gp=0.jpg", 500));
        data.add(new LiveDataBean("https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00553-3963.jpg", 100));
        data.add(new LiveDataBean("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1186710844,269686722&fm=15&gp=0.jpg", 100));
        data.add(new LiveDataBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1592679528,3428712183&fm=26&gp=0.jpg", 500));
        data.add(new LiveDataBean("https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00553-3963.jpg", 100));
        data.add(new LiveDataBean("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1186710844,269686722&fm=15&gp=0.jpg", 100));
        data.add(new LiveDataBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1592679528,3428712183&fm=26&gp=0.jpg", 500));
        data.add(new LiveDataBean("https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00553-3963.jpg", 100));
        data.add(new LiveDataBean("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1186710844,269686722&fm=15&gp=0.jpg", 100));
        data.add(new LiveDataBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1592679528,3428712183&fm=26&gp=0.jpg", 500));
        data.add(new LiveDataBean("https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00553-3963.jpg", 100));
        data.add(new LiveDataBean("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1186710844,269686722&fm=15&gp=0.jpg", 100));
        data.add(new LiveDataBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1592679528,3428712183&fm=26&gp=0.jpg", 500));
        adapter.setData(data);
    }

    @Override
    public void onAttach(@NonNull Context context) {
        mContext = context;
        super.onAttach(context);
    }

}
